package com.test.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.test.common.Page;
import com.test.dao.UserDao;
import com.test.entity.User;
import com.test.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao userDao;

	@Override
	public Map<String, Object> findByPage(String currentPage, String pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, Object> result = new HashMap<String, Object>();
		//设置分页相关属性到Page类
		Page page = new Page();
		if(currentPage != null && !"".equals(currentPage)) {
			page.setPageNo(Integer.valueOf(currentPage));
		}
		if(pageSize != null && !"".equals(pageSize)) {
			page.setPageSize(Integer.valueOf(pageSize));
		}
		// map中添加查询条件page，使用map可以添加其它与分页无关的查询条件
		params.put("page", page);
		List<User> list = userDao.findByPage(params);
		// 添加查询结果
		result.put("data", list);
		result.put("totalRow", page.getTotalRow());
		result.put("totalPage", page.getTotalPage());
		return result;
	}

}
